package proj.client;

import java.util.List;
import java.util.Scanner;

import proj.common.Request;
import proj.common.Response;

public class NovelClient {
	SocketClient s = new SocketClient();
	Scanner in = new Scanner(System.in);

	public void start() {
		System.out.println("欢迎使用迷你小说阅读器");
		while (true) {
			System.out.println("1:登录.2:注册.3:退出");
			System.out.println("请选择：");
			int ch = in.nextInt();
			switch (ch) {
			case 1:
				login();
				break;
			case 2:
				reg();
				break;
			case 3:
				//
				close();
				//

				return;
			default:
				System.out.println("无此选项！");
				break;
			}
		}
	}

	public void close() {
		Request req = new Request("logout");
		Response resp = s.send(req);
		s.close();
	}

	public void login() {
		System.out.println("输入用户名和密码：");
		String name = in.next();
		String pass = in.next();
		Request req = new Request("login");
		req.put("userName", name);
		req.put("userpass", pass);
		Response resp = s.send(req);
		if (resp.isSucess() == false) {
			System.out.println(resp.getMsg());
			return;
		}
		chooseType();
	}

	// 选择小说类型
	public void chooseType() {
		//
		System.out.println("1：武侠，2：言情");
		int ch = in.nextInt();
		Request req = new Request("getNovelBytType");

		if (ch == 1) {
			req.put("type", "武侠");
		} else if (ch == 2) {
			req.put("type", "武侠");
		} else {
			System.out.println("输出没有对应的类型");
			chooseType();
			return;
		}
		//
		Response resp = s.send(req);
		if (resp.isSucess() == false) {
			System.out.println(resp.getMsg());
			return;
		}
		// 获得小说列表
		List list = (List) resp.get("novellist");

	}

	public void reg() {
		System.out.println("输入用户名：");
		String name = in.next();
		System.out.println("请输入密码：");
		String pass = in.next();
		System.out.println("再次输入密码：");
		String repass = in.next();
		Request req = new Request("reg");
		req.put("name", name);
		req.put("pass", pass);
		Response resp = s.send(req);
		System.out.println(resp.getMsg());
	}

	public static void main(String[] args) {
		NovelClient client = new NovelClient();
		client.start();
	}

}
